package de.ifi.lmu.snitzelhunt.view;

import java.util.ArrayList;


import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import de.ifi.lmu.snitzelhunt.R;

import de.ifi.lmu.snitzelhunt.util.basics.Ranking;

/**
 * 
 * Class sets fills the list of the ranking view and matches the layout to the Rankings items
 * 
 * @author Sarah Torma
 *
 */
public class RankListViewAdapter extends ArrayAdapter<Ranking> {

		private final Context context;
		private final ArrayList<Ranking> values;
		
		private TextView name;
		private TextView number;
		private TextView score;

		public RankListViewAdapter(Context context, ArrayList<Ranking> values) {
			super(context, R.layout.rankinglist_layout,values);
			this.context = context;
			this.values = values;
		}
		
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			View rowView = inflater.inflate(R.layout.rankinglist_layout, parent, false);
			
			name = (TextView) rowView.findViewById(R.id.RankingListName);
			number = (TextView) rowView.findViewById(R.id.rankingListIndex); 
			score = (TextView) rowView.findViewById(R.id.RankingListScore);
			
			Log.i("Adapter", "Name:"+(name!=null));
		    if(name==null)
		    {
		    	System.out.println("no field for name");
		    }
			
			
			name.setText(values.get(position).getRanking_name());
			
			
			Log.i("Adapter", "number:"+(number!=null));
			number.setText(position+1+"");
			
			
		    score.setText(String.valueOf(values.get(position).getRanking()));
			
			return rowView;
		}
		
		
	

}





